/*
 * @Author: scl
 * @Date: 2023-08-22 18:42:04
 * @LastEditTime: 2023-09-09 22:17:08
 * @Description: file content
 */
var canFinish = function(numCourses, prerequisites) {
    const edges = Array.from(new Array(numCourses), x => new Array()), visited = new Array(numCourses).fill(0)
    let valid = true;
    for(let info of prerequisites){
        edges[info[1]].push(info[0])
    }
    for (let i = 0; i < numCourses && valid; ++i) {
        if (!visited[i]) {
            dfs(i);
        }
    }
    console.log(valid)
    return valid;
    function dfs(u) {
        visited[u] = 1;
        for (const v of edges[u]) {
            if (visited[v] == 0) {
                dfs(v);
                if (!valid) {
                    return;
                }
            }
            else if (visited[v] == 1) {
                valid = false;
                return;
            }
        }
        visited[u] = 2;
    }
}
canFinish(3,[[1,0],[2,1],[2,0]])